﻿using BLL;
using System;

namespace Thksoft.BusinessExpansion.Business
{
    public partial class UserInfo1 : BaseUI.BasePage
    {
        private Sys_UserBLL userBLL = new Sys_UserBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var entity = userBLL.GetInfoById(CurrentUserID.ToString().Trim());
                FORM_LOGIN_NAME.Text = entity.USER_LOGINNAME;
                FORM_USER_NAME.Text = entity.USER_NAME;
                FORM_SEX.SelectedValue = entity.USER_SEX;
                FORM_PHONE.Text = entity.USER_PHONE;
                FORM_JOB_STATUS.Text = entity.USER_JOBSTATUS.Trim() == "0" ? "离职" : "在职";
                FORM_LOGIN_DATE.Text = entity.USER_LOGINTIME.ToString("yyyy-MM-dd HH:mm:ss");
                FORM_COMPANY_NAME.Text = CurrentUserCompanyName;
                FORM_DEPARTMENT_NAME.Text = new Sys_DepartmentBLL().GetInfoById(CurrentUserDeptID.ToString().Trim()).DEPTNAME;
            }
        }

        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {
                var entity = userBLL.GetInfoById(CurrentUserID.ToString().Trim());
                entity.USER_SEX = FORM_SEX.SelectedValue;
                entity.USER_PHONE = FORM_PHONE.Text;
                entity.USER_NAME = FORM_USER_NAME.Text;
                if (userBLL.UPDATE(entity, CurrentUserName) > 0)
                {
                    MessageBox.Show(this, "【温馨提示】修改成功");
                }
                else
                {
                    MessageBox.Show(this, "【温馨提示】修改失败");
                }
            }
            catch (Exception)
            {
                MessageBox.Show(this, "【温馨提示】 发生异常");
            }
        }

        protected void btnCancle_Click(object sender, EventArgs e)
        {
            MessageBox.ResponseScript(this, "FORM_CLOSE();");
        }
    }
}